﻿<!--
* Module Name:	TreeViewCrudDragDrop.xaml
* Project:		MvvmTreeView
* Copyright (c) Microsoft Corporation.
* 
* XAML representation of Custom Silverlight User Control which implements 
* a TreeView with added functionalities of CRUD and Drag-And-Drop
* 
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
* 
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
    
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
-->
    
<UserControl 
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  
    x:Class="MvvmTreeView.WindowsStyleTreeView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="500" d:DesignWidth="500"
    Margin="0, 0, 0 ,0" Width="Auto" Height="Auto"
    xmlns:local="clr-namespace:MvvmTreeView.Converters"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit" 
    xmlns:my="clr-namespace:MvvmTreeView" Loaded="UserControl_Loaded">
    
    <UserControl.Resources>

        <local:ByteArrayToBitMapConverter x:Key="ArrayToBitmap" />

        <!-- Template for Edit mode of TreeViewItem -->
        <sdk:HierarchicalDataTemplate x:Key="TreeViewMainEditTemplate" 
                                      ItemsSource="{Binding Nodes}">
            <TextBox Text="{Binding Text,Mode=TwoWay}">
            </TextBox>
        </sdk:HierarchicalDataTemplate>
        <!-- Template for Read mode for TreeViewItem -->
        <sdk:HierarchicalDataTemplate x:Key="TreeViewMainReadTemplate" 
                                      ItemsSource="{Binding Nodes}">
            <my:TreeNodeItemContent NodeContentCreated="TreeNodeItem_NodeContentCreated" Text="{Binding Text,Mode=TwoWay}" Tag="{Binding BindsDirectlyToSource=True}" Foreground="Black"
                        MouseRightButtonDown="TreeViewMain_MouseRightButtonDown" 
                        MouseRightButtonUp="TreeViewMain_MouseRightButtonUp" 
                        MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown">
            </my:TreeNodeItemContent>
            <!--Image="{Binding ImageData, Converter={StaticResource ArrayToBitmap}}"-->
        </sdk:HierarchicalDataTemplate>        
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White" Margin="0, 0, 0 ,0" Width="Auto" Height="Auto">
        <!-- TreeViewDragDropTarget from Toolkit to add DragAndDrop feature -->
        <my:WindowsStyleTreeViewDragDropTarget x:Name="DragDropTarget" AllowDrop="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" 
                                        DragEnter="TreeViewDragDropTarget_DragEnter"
                                        DragLeave="TreeViewDragDropTarget_DragLeave"
                                        DragOver="TreeViewDragDropTarget_DragOver" 
                                        GiveFeedback="DragDropTarget_GiveFeedback"
                                        QueryContinueDrag="DragDropTarget_QueryContinueDrag"
                                        ItemDragStarting="DragDropTarget_ItemDragStarting"
                                        ItemDragCompleted="DragDropTarget_ItemDragCompleted"
                                        ItemDroppedOnSource="DragDropTarget_ItemDroppedOnSource"
                                        ItemDroppedOnTarget="DragDropTarget_ItemDroppedOnTarget"
                                        AllowedSourceEffects="Copy,Link,Move,Scroll,None,All">
            <!-- Custom TreeView  -->
            <sdk:TreeView Name="TreeViewMain" Margin="0, 0, 0 ,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding TreeView.Nodes}" 
                        ItemTemplate="{StaticResource TreeViewMainReadTemplate}"
                        MouseRightButtonDown="TreeViewMain_MouseRightButtonDown" 
                        MouseRightButtonUp="TreeViewMain_MouseRightButtonUp" 
                        MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown" 
                        HorizontalContentAlignment="Stretch" 
                        VerticalContentAlignment="Stretch" 
                        TabNavigation="Cycle" 
                        SelectedItemChanged="TreeViewMain_SelectedItemChanged"
                        Loaded="TreeViewMain_Loaded"  >
            </sdk:TreeView>
        </my:WindowsStyleTreeViewDragDropTarget>
    </Grid>
    
</UserControl>
